function HandleDialogDetails(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  
  this._purchases = (options && options.purchases) ? options.purchases : [];
  this._orderId = (options && options.orderId) ? options.orderId : null;
  this._hidePrice = (options && options.hidePrice) ? options.hidePrice : false;

  this._createElements();
};

HandleDialogDetails.prototype._createElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui);
  
  this._albums = [];
  if (this._item.pi_type == '{{$smarty.const.SAMPLE_TYPE_ALBUM|escape:javascript}}' || this._item.pi_type == '{{$smarty.const.SAMPLE_TYPE_MAGAZINE|escape:javascript}}') {
    this._albums[this._albums.length] = this._item;
  }
  if (this._item.cancelled == 0) {
    for (var i = 0, il = this._purchases.length; i < il; i++) {
      var purchase = this._purchases[i];
      if (purchase.cancelled) {
        continue;
      }
      if (purchase.trackId != this._item.pi_trackId && (purchase.type == '{{$smarty.const.SAMPLE_TYPE_ALBUM|escape:javascript}}' || purchase.type == '{{$smarty.const.SAMPLE_TYPE_MAGAZINE|escape:javascript}}')) {
        this._albums[this._albums.length] = purchase;
      }
    }
  }
  MiscUtils.sort(this._albums, ['pi_otherId']);

  this._designs = {};
  for (var i = 0, il = this._albums.length; i < il; i++) {
    var album = this._albums[i];
    
    if (this._designs[album.pi_otherId] == undefined) {
      this._designs[album.pi_otherId] = [album];
    } else {
      this._designs[album.pi_otherId][this._designs[album.pi_otherId].length] = album;
    }
  }

  this._gui.sample.style.color = '#ff0000';
  this._gui.sample.appendChild(document.createTextNode(this._item.pi_name));
  this._gui.quantity.style.color = '#ff0000';
  this._gui.quantity.appendChild(document.createTextNode(this._item.pi_quantity));
  this._gui.price.style.color = '#ff0000';
  
  this._gui.quantityPic.style.display = 'none';
  this._gui.quantity.style.display = 'none';
  
  this._gui.pricePic.style.display = (this._hidePrice) ? 'none' : 'block';
  
  this._gui.price.appendChild(document.createTextNode((this._hidePrice) ? '' : this._item.pi_total));
  
  for (var i = 0, il = this._item.pi_selects.length; i < il; i++) {
    var select = this._item.pi_selects[i];
    var gselect = this._gui.selects[i];
    gselect.name.appendChild(document.createTextNode(select.title));
    gselect.option.style.color = '#ff0000';
    gselect.option.appendChild(document.createTextNode(select.value));
  }
  
  this._loadData();
};

HandleDialogDetails.prototype._loadData = function() {
  this._produces = null;

  this._retrieveProduces();
};

HandleDialogDetails.prototype._verifyData = function() {
  if (this._produces) {
    this._updateElements();
  }
};

HandleDialogDetails.prototype._retrieveProduces = function() {
  var _self = this;
  if (this._gui.design && this._orderId) {
    this._gui.design.appendChild(DOMUtils.getLoadingImage());
    var joins = '&selects=0' + '&purchaseitems=1' + '&preconusers=0' + '&events=0' + '&tracks=0' + '&produces=0' + '&notes=0';
    var args = '&c=d.orderId=' + this._orderId + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, { php: 'customphp/produceread.php' });
  } else {
    this._produces = [];
    this._updateElements();
  }
};

HandleDialogDetails.prototype._updateElements = function() {
  var table, td, tr;

  var exists = false;
  if (this._gui.design) {
    DOMUtils.removeChildElements(this._gui.design);
    table = document.createElement('table');
    this._gui.design.appendChild(table);
    for (var i = 0, il = this._produces.length; i < il; i++) {
      var produce = this._produces[i];
      if (produce.pi_model == '{{$smarty.const.MODEL_NAME_ALBUM_DESIGN|escape:javascript}}' && produce.pi_trackId == this._item.pi_trackId) {
        exists = true;
        tr = table.insertRow(-1);
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('相册 (' + DlmanageUtils.congregate4(produce.v2_purchaseItems).title + ')'));
      } else if (this._item.cancelled == 0 && this._item.pi_model == '{{$smarty.const.MODEL_NAME_PRODUCT_COMMON|escape:javascript}}' && (this._item.pi_type == '{{$smarty.const.SAMPLE_TYPE_ALBUM|escape:javascript}}' || this._item.pi_type == '{{$smarty.const.SAMPLE_TYPE_MAGAZINE|escape:javascript}}') && produce.pi_trackId == this._item.pi_otherId) {
        exists = true;
        tr = table.insertRow(-1);
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('相册设计(' + produce.title + ')'));
      }
    }
    
    if (!exists && this._designs[this._item.pi_otherId]) {
      for (var otherId in this._designs) {
        var other = DlmanageUtils.congregate3(this._designs[otherId]);
        if (this._item.pi_otherId != otherId) {
          continue;
        }
        tr = table.insertRow(-1);
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode('相册设计 (' + other.title + ')'));
      }
    }
  }
};